<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试数据迁移功能</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .section {
            margin: 20px 0;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        button {
            padding: 10px 15px;
            margin: 5px;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        .primary { background: #007bff; color: white; }
        .success { background: #28a745; color: white; }
        .danger { background: #dc3545; color: white; }
        .info { background: #17a2b8; color: white; }
        pre {
            background: #f8f9fa;
            padding: 10px;
            border-radius: 3px;
            overflow-x: auto;
        }
    </style>
</head>
<body>
    <h1>数据迁移功能测试</h1>
    
    <div class="section">
        <h2>1. 准备测试数据</h2>
        <button class="primary" onclick="createTestData()">创建测试数据</button>
        <button class="info" onclick="viewLocalStorage()">查看localStorage</button>
        <button class="danger" onclick="clearTestData()">清除测试数据</button>
    </div>
    
    <div class="section">
        <h2>2. 迁移状态控制</h2>
        <button class="info" onclick="checkMigrationStatus()">检查迁移状态</button>
        <button class="danger" onclick="resetMigrationStatus()">重置迁移状态</button>
    </div>
    
    <div class="section">
        <h2>3. 测试迁移功能</h2>
        <p>创建测试数据后，访问主应用 <a href="http://localhost:5173" target="_blank">http://localhost:5173</a> 来测试迁移功能</p>
    </div>
    
    <div class="section">
        <h2>输出</h2>
        <pre id="output"></pre>
    </div>

    <script>
        function log(message) {
            const output = document.getElementById('output');
            output.textContent += new Date().toLocaleTimeString() + ': ' + message + '\n';
        }

        function createTestData() {
            const testAgents = [
                {
                    id: 'test-agent-1',
                    name: '测试智能体1',
                    description: '这是第一个测试智能体',
                    avatar: '🤖',
                    prompt: '你是一个测试助手',
                    createdAt: new Date().toISOString(),
                    updatedAt: new Date().toISOString()
                },
                {
                    id: 'test-agent-2', 
                    name: '测试智能体2',
                    description: '这是第二个测试智能体',
                    avatar: '🎯',
                    prompt: '你是一个专业的测试工具',
                    createdAt: new Date().toISOString(),
                    updatedAt: new Date().toISOString()
                },
                {
                    id: 'test-agent-3',
                    name: '测试智能体3', 
                    description: '这是第三个测试智能体',
                    avatar: '⚡',
                    prompt: '你是一个高效的助手',
                    createdAt: new Date().toISOString(),
                    updatedAt: new Date().toISOString()
                }
            ];
            
            localStorage.setItem('agents', JSON.stringify(testAgents));
            log('已创建 ' + testAgents.length + ' 个测试智能体数据');
        }

        function viewLocalStorage() {
            const agents = localStorage.getItem('agents');
            const migrationStatus = localStorage.getItem('migration_completed');
            
            log('=== localStorage 内容 ===');
            log('agents: ' + (agents ? JSON.parse(agents).length + ' 个智能体' : '无数据'));
            log('migration_completed: ' + (migrationStatus || '未设置'));
            
            if (agents) {
                const agentData = JSON.parse(agents);
                agentData.forEach((agent, index) => {
                    log(`智能体${index + 1}: ${agent.name} (${agent.id})`);
                });
            }
        }

        function clearTestData() {
            localStorage.removeItem('agents');
            log('已清除测试数据');
        }

        function checkMigrationStatus() {
            const status = localStorage.getItem('migration_completed');
            log('迁移状态: ' + (status === 'true' ? '已完成' : '未完成'));
        }

        function resetMigrationStatus() {
            localStorage.removeItem('migration_completed');
            log('已重置迁移状态');
        }

        // 页面加载时显示当前状态
        window.onload = function() {
            log('测试页面已加载');
            viewLocalStorage();
        };
    </script>
</body>
</html>